import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'UniversityCourse.dart';

class UniversityIndexPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _UniversityIndexState();
  }
}

class _UniversityIndexState extends State<UniversityIndexPage> {
  var _currentIndex = 0;
  var tabTxt = <String>["课程", "考试", "我的"];
  PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController(initialPage: _currentIndex);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize:
            Size.fromHeight(MediaQuery.of(context).size.height * 0.07),
        child: SafeArea(
          top: true,
          child: Offstage(),
        ),
      ),
      body: Container(
        color: Colors.white,
        child: PageView(
          controller: _pageController,
          children: _page,
          onPageChanged: _onItemTapped,
        ),
      ),
      bottomNavigationBar: _initBottomBar(),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }

  //初始化底部的bottomNavigationBar
  BottomNavigationBar _initBottomBar() {
    return BottomNavigationBar(
      items: <BottomNavigationBarItem>[
        BottomNavigationBarItem(
            icon: ImageIcon(
                AssetImage("assets/university/images/home_img_n_kc.png")),
            title: Text('课程')),
        BottomNavigationBarItem(
            icon: ImageIcon(
                AssetImage("assets/university/images/home_img_n_ks.png")),
            title: Text('考试')),
        BottomNavigationBarItem(
            icon: ImageIcon(
                AssetImage("assets/university/images/home_img_n_wd.png")),
            title: Text('我的')),
      ],
      currentIndex: _currentIndex,
      fixedColor: Color.fromARGB(255, 211, 177, 127),
      onTap: _onItemTapped,
    );
  }

  //联动操作
  _onItemTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  //页面数据
  List<Widget> _page = [
    UniversityCourse(),
    UniversityCourse(),
    UniversityCourse()
  ];
}
